package cn.stylefeng.guns.modular.order.controller;

import cn.hutool.core.util.IdUtil;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.order.entity.WeightPrice;
import cn.stylefeng.guns.modular.order.model.params.WeightPriceParam;
import cn.stylefeng.guns.modular.order.model.result.WeightPriceResult;
import cn.stylefeng.guns.modular.order.service.WeightPriceService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 重量与价格表控制器
 *
 * @author zhou
 * @Date 2019-08-05 15:02:24
 */
@Controller
@RequestMapping("/weightPrice")
public class WeightPriceController extends BaseController {

    private String PREFIX = "/order/weightPrice";

    @Autowired
    private WeightPriceService weightPriceService;

    /**
     * 跳转到主页面
     *
     * @author zhou
     * @Date 2019-08-05
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/weightPrice.html";
    }

    /**
     * 新增页面
     *
     * @author zhou
     * @Date 2019-08-05
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/weightPrice_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhou
     * @Date 2019-08-05
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/weightPrice_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zhou
     * @Date 2019-08-05
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(WeightPriceParam weightPriceParam) {
        this.weightPriceService.add(weightPriceParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhou
     * @Date 2019-08-05
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(WeightPriceParam weightPriceParam) {
        this.weightPriceService.update(weightPriceParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhou
     * @Date 2019-08-05
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(WeightPriceParam weightPriceParam) {
        this.weightPriceService.delete(weightPriceParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhou
     * @Date 2019-08-05
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(WeightPriceParam weightPriceParam) {
        WeightPrice detail = this.weightPriceService.getById(weightPriceParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zhou
     * @Date 2019-08-05
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(WeightPriceParam weightPriceParam) {
        return this.weightPriceService.findPageBySpec(weightPriceParam);
    }


    @ResponseBody
    @RequestMapping("/lists")
    public ResponseData lists() {
        List<WeightPriceResult> WeightPriceResults = weightPriceService.getAll();
        return ResponseData.success(WeightPriceResults);

    }
}


